<!--
* description: 设置信息维护
* author:wangjuan
* createdDate:
-->
<template>
  <section class="editSetBelow">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="70%"
      :before-close="handleClose"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="titleName"
        :style-type="$store.state.app.dialogType"
      />

      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          :fixed="true"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from '@/components/mixins/formMixins'
import api from '@/api/belowInfo'

export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader'), // 弹窗标题
    mixButton: () => import('@/components/basicComponent/mixButton')
  },
  // 组件混入对象
  mixins: [formMixins],
  props: {
    settingData: { type: Object, default: () => {} }
  },

  data() {
    const viewPageCode = 'setBelow-edit'
    return {
      titleName: '设置展车',
      // 保存API配置对象
      // apiConfig: orgApis.mdmOrgInfoMutationSupplierSave,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.save(),
          text: this.$t('sys.button.save') /* 保存*/,
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          icon: 'iconfont icon-cancel',
          clickEvent: () => this.sendCode('0'),
          text: this.$t('sys.button.cancel') // 取消
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '展车标记：',
              codeField: 'exCarType',
              disabled: true,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '展车车主：',
              codeField: 'signatoryname',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '车主电话：',
              codeField: 'signatoryphone',
              validrule: { isPhone: true, maxlength: 11 },
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '车主邮箱：',
              codeField: 'email',
              validrule: { isEmail: true },
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '展车说明：',
              codeField: 'remark',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            }
          ],

      // 标题
      textMap: {
        edit: '展车信息维护'
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(this, {
        signatoryname: '',
        signatoryphone: '',
        email: '',
        remark: '',
        exCarType: '' // 标记展车
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  created() {},
  mounted() {
    this.formField.exCarType = this.settingData.exCarType === '是' ? '展车' : '非展车'
  },
  methods: {
    save() {
      const obj = {
        saleOrderDId: this.settingData.saleOrderDId,
        updateControlIdOd: this.settingData.updateControlIdOd,
        updateControlIdS: this.settingData.updateControlIdS
      }
      // // 先读取参数中的传输对象
      const returnObj = {
      // api配置
        apiConfig: api.updateExhibitionCarSetting,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: Object.assign(obj, this.formField)
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(returnObj, null, this.dynamicApiStyle)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD, this.dynamicApiStyle).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              duration: 2000
            })
          }
          return
        }
        this.$message({ message: response.msg })
        this.sendCode('1')
      }).catch(_ => {})
    },

    // 关闭弹窗
    handleClose(done) {
      this.$confirm('还未保存，确认关闭窗口？')
        .then(_ => {
          this.$emit('update:popupsVisible', false)
          done()
        })
        .catch(_ => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.promptSpan{
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>
